class ConfigParser:
    def __init__(self):
        self.res_dic = {}

    def read(self, file):
        try:
            with open(file, mode="r", encoding="utf-8") as f:
                for i in f.read().split("\n"):
                    if i != '':
                        key, value = i.split("=")
                        if key not in self.res_dic:
                            self.res_dic.update({key: value})
                        else:
                            raise DuplicateSectionError()
        except Exception:
            raise FileNotExistError()

    def get(self, key):
        return self.res_dic.get(key, None)


class FileNotExistError(Exception):
    def __str__(self):
        return "文件不存在"


class DuplicateSectionError(Exception):
    def __str__(self):
        return "配置项重复"
